import * as monaco from 'monaco-editor';
import { acceptHMRUpdate, defineStore } from 'pinia';

import config from '@/model/config';

interface EditorState {
  options: monaco.editor.IStandaloneEditorConstructionOptions;
}

export const useEditorStore = defineStore('wos-editor', {
  actions: {
    /**
     * @description: 修改编辑器设置
     */
    updateOptions(options: monaco.editor.IStandaloneEditorConstructionOptions) {
      this.options = options;
    },
  },
  persist: true,
  state: (): EditorState => ({
    options:
      config.monocaDefaultConfig as monaco.editor.IStandaloneEditorConstructionOptions,
  }),
});

// 解决热更新问题
const hot = import.meta.hot;
if (hot) {
  hot.accept(acceptHMRUpdate(useEditorStore, hot));
}
